home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre1.z / postgre1 / test / iportal1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  2.2 KB  |  85 lines

  1. /*
  2.  * Testing of new binary portal interface.
  3.  * 
  4.  * Do the following at the monitor:
  5.  *
  6.  
  7.  create test1 (i1 = int4, i2 = int2, d = float4,p = polygon) \g
  8.  append test1 (i1 = 7, d=3.567,p="(1.0,2.0,3.0,4.0)"::polygon) \g
  9.  append test1 (i1 = 7, i2 = 3, d=3.567,p="(1.0,2.0,3.0,4.0)"::polygon) \g
  10.  
  11.  -- Anything else you can think of. 
  12.  * Start up this program.
  13.  * The correct contents of test1 should be printed
  14.  *
  15.  *    $Header: /private/postgres/test/RCS/iportal1.c,v 1.3 1992/07/29 18:23:39 clarsen Exp $
  16.  */
  17.  
  18. #include "tmp/simplelists.h"
  19. #include "tmp/libpq.h"
  20. #include "utils/geo-decls.h"
  21.  
  22. void main()
  23. {
  24.     extern int PQAsyncNotifyWaiting;
  25.     PQNotifyList *l;
  26.     PortalBuffer *portalbuf;
  27.     char *res;
  28.     int ngroups,tupno, grpno, ntups, nflds;
  29.     PQsetdb(getenv("USER"));
  30.  
  31.     PQexec("begin");
  32.     res = (char *)PQexec("retrieve iportal junk (test1.all)");
  33.     if (*res == 'E') {
  34.     fprintf(stderr,"%s\nfailed",++res);
  35.     goto exit_error;
  36.     }
  37.     res = (char *)PQexec("fetch all in junk");
  38.     if (*res != 'P') {
  39.     fprintf(stderr,"\nno portal");
  40.     goto exit_error;
  41.     }
  42.     /* get tuples in relation */
  43.     portalbuf = PQparray(++res);
  44.     ngroups = PQngroups(portalbuf);
  45.     for (grpno = 0; grpno < ngroups; grpno++) {
  46.     ntups = PQntuplesGroup(portalbuf, grpno);
  47.     if ((nflds = PQnfieldsGroup(portalbuf, grpno)) != 4) {
  48.         fprintf(stderr, "expected 4 attributes, got %d\n", nflds);
  49.         goto exit_error;
  50.     }
  51.     for (tupno = 0; tupno < ntups; tupno++) {
  52.         int *bla1;
  53.         char *bla2;
  54.         POLYGON *bla3;
  55.         int16 *bla4;
  56.         bla1 = (int *)PQgetvalue(portalbuf,tupno,0);
  57.         bla4 = PQgetvalue(portalbuf,tupno,1);
  58.         bla2 = PQgetvalue(portalbuf,tupno,2);
  59.         bla3 = PQgetvalue(portalbuf,tupno,3)-4;
  60.  
  61.         printf ("got i1=%d(%d bytes), i2=%d(%d bytes), d=(%f)(%d bytes)|%x|%x|%x|%x\n\
  62.  Polygon(%d bytes)\
  63.   %d points (%f,%f,%f,%f)\n",
  64.             *bla1,PQgetlength(portalbuf,tupno,0),
  65.             *bla4,PQgetlength(portalbuf,tupno,1),
  66.             *((float *)bla2),
  67.             PQgetlength(portalbuf,tupno,2),
  68.             *bla2,*(bla2+1),*(bla2+2),*(bla2+3),
  69.             PQgetlength(portalbuf,tupno,3),
  70.             bla3->npts,
  71.             bla3->boundbox.xh,bla3->boundbox.yh,
  72.             bla3->boundbox.xl,bla3->boundbox.yl);
  73.     }
  74.     }
  75.  
  76.     PQexec("end");
  77.     PQfinish();
  78.     exit(0);
  79.   exit_error:
  80.     PQexec("end");
  81.     PQfinish();
  82.     exit(1);
  83.  
  84. }
  85.